package me.ilich.piet.interpreter;

import java.security.InvalidParameterException;

public final class Coordinate {
	
	public static Coordinate instance(int x, int y){
		if(x<0) throw new InvalidParameterException("x");
		if(y<0) throw new InvalidParameterException("y");
		Coordinate coordinate = new Coordinate(x, y);
		return coordinate;
	}
	
	private final int mX;
	private final int mY;
			
	private Coordinate(int x, int y){
		mX = x;
		mY = y;
	}
	
	public int getX(){
		return mX;
	}
	
	public int getY(){
		return mY;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + mX;
		result = prime * result + mY;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Coordinate other = (Coordinate) obj;
		if (mX != other.mX)
			return false;
		if (mY != other.mY)
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		return "(" + mX + "," + mY + ")";
	}

}
